# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name：     job_tech
   Description :
   Author :       Flyoung
   date：          2023/9/5
-------------------------------------------------
   Change Activity:
                   2023/9/5:
-------------------------------------------------
"""
from sqlalchemy import Column, Integer, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Session

from db.common import with_session

Base = declarative_base()


class JobTech(Base):
    __tablename__ = 'job_tech'

    job_tech_id = Column(Integer, primary_key=True, autoincrement=True)
    job_id = Column(Integer)
    tech_id = Column(Integer)

    def __init__(self, job_id, tech_id):
        self.job_id = job_id
        self.tech_id = tech_id

    def to_dict(self):
        return {
            'job_tech_id': self.job_tech_id,
            'job_id': self.job_id,
            'tech_id': self.tech_id
        }


@with_session
def add_job_tech(session: Session, job_id, tech_id):
    jt = JobTech(job_id, tech_id)
    session.add(jt)
    return jt.to_dict()
